<%-- 
    Document   : index
    Created on : Apr 4, 2011, 10:15:59 PM
    Author     : Yongke
--%>

<%@page import="javax.security.auth.RefreshFailedException"%>
<%@page import="java.util.Enumeration"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="StyleSheet" href="index.css" type="text/css" />
        <title>MyRC</title>
    </head>
    <body>
		<%
			Boolean isBanned = true; //Check if user is not banned
			String uname = "null";
			if(session.getAttribute("username") != null)
                            uname = session.getAttribute("username").toString();

                        out.println("uname = " + uname);

			if(!uname.equals("null"))
			{
				Class.forName("com.mysql.jdbc.Driver").newInstance();
				String connectionUrl = "jdbc:mysql://localhost/myrc?"+"user=progin&password=progin";
				Connection con = DriverManager.getConnection(connectionUrl);

				Statement stmt = null;
				ResultSet rs = null;

				String SQL = "SELECT * FROM user WHERE Username = '" + uname + "'";
				stmt = con.createStatement();
				rs = stmt.executeQuery(SQL);

				while(rs.next()){
					if( (rs.getString("StatusBan")).equals("0") && rs.getString("Online").equals("1")){
						isBanned = false;
					}
				}
			}
		%>
        <div id="header"><img src="title.png" width="30%"></div>
        <div id="body">
			<%
				if(isBanned){
			%>
            <div class="login">
                <form name="formlogin" action="login" method="POST">
                    <table border="0">
                        <thead>
                            <tr>
                                <th></th>
                                <th></th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td>UserName :</td>
                                <td><input type="text" name="username"></td>
                            </tr>
                            <tr>
                                <td>Password :</td>
                                <td><input type="password" name="password"></td>
                            </tr>
                        </tbody>
                    </table>
                    <input type=submit value="Login">
                </form>
            </div>
            <div class="registrasi">
                <form action="registrasi" method="post">
                    <label>SignUp? it's free!<br></label>
                    Name:    <input type="text" name="name"><br>
                    Username: <input type="text" name="userreg"><br>
                    Email:    <input type="text" name="email"><br>
                    Password: <input type="password" name="passreg"><br>
                    Confirm Password: <input type="password" name="confirmpassreg"><br>
                    <input type=submit value="Registrasi">
                </form>
            </div>
			<%
				} else { //User is already logged in and not banned
					response.sendRedirect("home.jsp");
				}
			%>
        </div>
        <div id="footer"></div>

    </body>
</html>
